<%@page import="models.DealStatistic"%>
<%@page import="models.StaffModel"%>
<%@page import="admin.data.StaffData"%>
<%@page import="models.DealModel"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Locale"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="helpers.DateHelper"%>
<%@page import="models.GeoModel"%>
<%@page import="admin.data.GeoData"%>
<%@page import="models.OrderModel"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%
	List<DealStatistic> listDealStatistic = (List<DealStatistic>) request.getAttribute("listDealStatistic");
	int currentPage = (Integer)request.getAttribute("page");	
	boolean isHasNextPage = (Boolean)request.getAttribute("isHasNextPage");	
	boolean isHasPreviousPage = (Boolean)request.getAttribute("isHasPreviousPage");	
	StaffData staffData = new StaffData();
	String url = (String)request.getAttribute("url");		
	String parameter = "";
	String dealId = "";
	String name = "";
	String username = "";		
	String status = "";
	if(request.getAttribute("dealId")!=null&&!request.getAttribute("dealId").toString().isEmpty()){
		dealId = (String)request.getAttribute("dealId");
		parameter += "&dealId=" + dealId;
	}	
	if(request.getAttribute("name")!=null&&!request.getAttribute("name").toString().isEmpty()){
		name = (String)request.getAttribute("name");
		parameter += "&name=" + name;
	}	
	if(request.getAttribute("username")!=null&&!request.getAttribute("username").toString().isEmpty()){
		username = (String)request.getAttribute("username");
		parameter += "&username=" + username;
	}		
	if(request.getAttribute("status")!=null&&!request.getAttribute("status").toString().isEmpty()){
		status = (String)request.getAttribute("status");
		parameter += "&status=" + status;
	}		
	int totalMoney = 0;
	NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
%>

<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>
<script type="text/javascript" src="/admin/js/list_form.js"></script>
<script type="text/javascript" src="/admin/js/form-user.js"></script>
<script type="text/javascript" src="/admin/js/list_deal.js"></script>
<script type="text/javascript" src="/admin/js/plugins/wysiwyg/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="/admin/js/plugins/wysiwyg/wysiwyg.image.js"></script>
<script type="text/javascript" src="/admin/js/plugins/wysiwyg/wysiwyg.link.js"></script>
<script type="text/javascript" src="/admin/js/plugins/wysiwyg/wysiwyg.table.js"></script>
<script type="text/javascript">
<!--
var server = "<%=UrlHelper.getServerUrl(request)%>";
//-->
</script>
        <div class="maincontent noright">
        	<div class="maincontentinner">
            	
               	<ul class="maintabmenu">
                	<li class="current"><a href="/admin/deal/manage">Thống kê Deal</a></li>
                	<li><a href="/admin/deal/list">Quản lý Deal</a></li>
                	<li><a href="/admin/deal/add">Tạo mới Deal</a></li>
                	<li><a href="/admin/ads/right">Quản lý Deal Quảng cáo</a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
                
                	<form class="stdform" action="/admin/deal/manage" method="post">
                    <div class="one_half">      
                    	<p>
                    		<label>Mã Deal : </label>
                            <span class="field"><input type="text" name="dealId" class="longinput" value="<%=(dealId!=null&&!dealId.isEmpty())?dealId:""%>"/></span>                
                    	</p>
                    	<p>
                    		<label>Tên Deal : </label>
                    		<span class="field"><input type="text" name="name" class="longinput" value="<%=(name!=null&&!name.isEmpty())?name:""%>"/></span>                  
                    	</p>                               	
                    	<p>
                    		<label>Tên Sale : </label>
                            <select id="username" name="username" class="smallinput">
                            	<option value="all">(Tất cả)</option>	
                            	<%
                            		for(StaffModel staff: staffData.getActiveListByRole(1)){
                            	%>
									<option value="<%=staff.getUsername() %>" <%=(username.equalsIgnoreCase(staff.getUsername()))?"selected":""%>><%=staff.getName() %></option>								
								<%
                            		}
								%>
							</select>                              
                    	</p>                       	           
						<p>
                    		<label>Trạng thái : </label>
                             <span class="field">
	                            <select name="status">
	                            	<option value="">Tất cả trạng thái</option>
	                            	<option value="0" <%=(status!=null&&status.equals("0"))?"selected":"" %>>Chưa kích hoạt</option>
	                                <option value="1" <%=(status!=null&&status.equals("1"))?"selected":"" %>>Đang kích hoạt</option>
	                                <option value="2" <%=(status!=null&&status.equals("2"))?"selected":"" %>>Đang chạy</option>
	                                <option value="3" <%=(status!=null&&status.equals("3"))?"selected":"" %>>Kết thúc</option>
	                                <option value="4" <%=(status!=null&&status.equals("4"))?"selected":"" %>>Đã khoá</option>
	                                <option value="5" <%=(status!=null&&status.equals("5"))?"selected":"" %>>Đã hoàn thành</option>	                            
	                            </select>
                            </span>                                
                    	</p>                       	                         
                    	<p class="stdformbutton">
	                     	<input type="submit" class="reset radius2" value="Tìm kiếm">
	                        <input type="reset" class="reset radius2" value="Làm lại">
	                     </p>                  	     	                    	        	                                        
                    </div><!--one_half-->     
                    <div class="one_half last">
                    	     
                    </div>               
                 	
                   </form> 
                   <br clear="all" /><br />                	
                	<div class="contenttitle radiusbottom0">
	                	<h2 class="table"><span>Danh sách Deal</span></h2>
	                </div>
	                
	                <div class="tableoptions">
	                    <select class="radius3 action-value">	                    			                    	                     
	                        <option value="lock">Khoá Deal</option>	                    
	                    </select> &nbsp;
	                    <button class="radius3 apply-change">Áp dụng</button>
	                </div>
	                
	                <table cellspacing="0" cellpadding="0" border="0" class="stdtable stdtablecb" id="list-table">
	                    <colgroup>
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                        <col class="con1">
	                    </colgroup>
	                    <thead>
	                        <tr>
	                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
	                            <th class="head1">Thao tác</th>
	                            <th class="head0">Mã Deal</th>
	                            <th class="head1">Tên Deal</th>
	                            <th class="head0">Trạng thái</th>
	                            <th class="head1">Ngưỡng tối đa</th>
	                            <th class="head1">SL DK</th>
	                            <th class="head0">SL đã giao</th>
	                            <th class="head1">SL đã TT</th>
	                            <th class="head0">SL đang giao</th>
	                            <th class="head1">Ngày bắt đầu</th>
	                            <th class="head0">Ngày kết thúc</th>
	                        </tr>
	                    </thead>	                   
	                    <tbody>
	                    	<% 
	                    		for (int i = 0; i < listDealStatistic.size(); i++) { 	                    			
	                    	%>
	                        <tr>
	                        	<td class="center">	           
	                        		<%
	                        		if(listDealStatistic.get(i).getDealStatus()!=0){
	                        		%>             		
	                        			<span class="checkbox"><input type="checkbox" value="<%=listDealStatistic.get(i).getDealId()%>"></span>
	                        		<%
	                        			}
	                        		%>	                        		
                        		</td>
								<td class="center">
									<%
										if(listDealStatistic.get(i).getDealStatus()!=0&&listDealStatistic.get(i).getDealStatus()!=4){
											%>
											<a title="Lock Deal" href="<%=listDealStatistic.get(i).getDealId()%>" class="lock_button">
												Khoá
											</a>|
											<%
										}else if(listDealStatistic.get(i).getDealStatus()!=0&&listDealStatistic.get(i).getDealStatus()==4){
											%>
											<a title="Unlock Deal" href="<%=listDealStatistic.get(i).getDealId()%>" class="unlock_button">
												Mở khoá
											</a>|
											<%
										}
										%>
										<a title="Sửa Deal" href="/admin/deal/edit?id=<%=listDealStatistic.get(i).getDealId()%>">
											Sửa
										</a>																										
								</td>
	                            <td> 
	                            	<%=listDealStatistic.get(i).getDealId() %>
	                            </td>
	                            <td>
	                            	<a title="Xem Deal" href="/<%=listDealStatistic.get(i).getDealId()%>/<%=listDealStatistic.get(i).getDealAlias() %>.<%=(listDealStatistic.get(i).getDealStatus()!=2)?"demo":"html" %>" target="blank">
	                            		 <%=listDealStatistic.get(i).getDealName() %>
	                            	</a>	                            		                            	
                            	</td>
                            	<td>
                            		<%
									switch (listDealStatistic.get(i).getDealStatus()) {
										case 0: 
											%>Chưa kích hoạt<%
											break;	
										case 1: 
											%>Đang kích hoạt<%
											break;	
										case 2: 
											%>Đang chạy<%
											break;
										case 3: 
											%>Kết thúc<%
											break;
										case 4: 
											%>Đã khoá<%
											break;
										case 5: 
											%>Hoàn thành<%
											break;
										default:
											%>Chưa kích hoạt<%
											break;											
									}
									%>									
                            	</td>
	                            <td class="center"><%=listDealStatistic.get(i).getMaximum() %></td>                            	
                            	<td class="center"><%=listDealStatistic.get(i).getOrderQuantity() %></td>
	                            <td class="center"><%=listDealStatistic.get(i).getDeliveredQuantity() %></td>
	                            <td class="center"><%=listDealStatistic.get(i).getPaidQuantity() %></td>
	                            <td class="center"><%=listDealStatistic.get(i).getTransportingQuantity() %></td>
	                            <td class="center"><%=DateHelper.dateToString(listDealStatistic.get(i).getStartTime(), "MM/dd/yyyy") %></td>
	                            <td class="center"><%=DateHelper.dateToString(listDealStatistic.get(i).getEndTime(), "MM/dd/yyyy") %></td>
	                        </tr>
	                        <% } %>
	                    </tbody>
	                </table>	                
	                <!-- paginate -->
	               <div class="dataTables_paginate paging_full_numbers" id="dyntable_paginate">	 	               	                          
	                	<% if (isHasPreviousPage) { %>
							<a class="previous paginate_button" id="dyntable_previous" 
							href="<%=url%>?page=<%=currentPage-1%><%=parameter%>">Trước</a>
						<% } else { %>
							<span class="previous paginate_button paginate_button_disabled" id="dyntable_previous">Trước</span>
						<% } %>
						<% if (isHasNextPage) { %>
							<a class="next paginate_button" id="dyntable_next"  
							href="<%=url%>?page=<%=currentPage+1%><%=parameter%>">Sau</a>
						<% } else { %>
							<span class="next paginate_button paginate_button_disabled" id="dyntable_next">Sau</span>
						<% } %>
	                </div>
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp">
            	<jsp:param name="language" value="1" />
			</jsp:include>
            
        </div><!--maincontent-->
        
<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>